from flask import Flask
import settings
from ext import db, cors, cache
# from apps.user.view import user_bp
from apps.apis.news_api import news_bp
from apps.apis.user_api import user_news_bp


config = {
    'CACHE_TYPE': 'redis',
    'CACHE_REDIS_HOST': '127.0.0.1',
    'CACHE_REDIS_PORT': 6379
}

def create_app():
    app = Flask(__name__, template_folder = '../templates', static_folder='../static')
    # 加载配置
    app.config.from_object(settings.ProductionConfig)
    # app.register_blueprint(user_bp)
    db.init_app(app)
    cors.init_app(app, supports_credentials=True)
    cache.init_app(app = app, config = config)
    app.register_blueprint(user_news_bp)

    print('*' * 50)
    print(app.url_map)
    print('*' * 50)

    return app